<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>CHM文件提取器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background-color: #f5f5f5;
        }
        .container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 30px;
        }
        .upload-form {
            text-align: center;
        }
        .file-input {
            display: none;
        }
        .file-label {
            display: inline-block;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border-radius: 4px;
            cursor: pointer;
            margin-bottom: 10px;
        }
        .file-label:hover {
            background-color: #45a049;
        }
        .submit-btn {
            padding: 10px 20px;
            background-color: #2196F3;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        .submit-btn:hover {
            background-color: #1976D2;
        }
        .submit-btn:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
        }
        .file-name {
            margin: 10px 0;
            color: #666;
        }
        .loading {
            display: none;
            margin-top: 20px;
        }
        .error {
            color: red;
            margin-top: 10px;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>CHM文件提取器</h1>
        <form class="upload-form" action="/extract" method="post" enctype="multipart/form-data">
            <label class="file-label" for="file">选择CHM文件</label>
            <input type="file" id="file" name="file" class="file-input" accept=".chm">
            <div class="file-name" id="fileName"></div>
            <button type="submit" class="submit-btn" id="submitBtn" disabled>提取文本</button>
        </form>
        <div class="loading" id="loading">
            正在处理文件，请稍候...
        </div>
        <div class="error" id="error">
            处理文件时出错，请重试
        </div>
    </div>

    <script>
        const fileInput = document.getElementById('file');
        const fileName = document.getElementById('fileName');
        const submitBtn = document.getElementById('submitBtn');
        const loading = document.getElementById('loading');
        const error = document.getElementById('error');

        fileInput.addEventListener('change', (e) => {
            const file = e.target.files[0];
            if (file) {
                fileName.textContent = '已选择: ' + file.name;
                submitBtn.disabled = false;
            } else {
                fileName.textContent = '';
                submitBtn.disabled = true;
            }
            error.style.display = 'none';
        });

        document.querySelector('form').addEventListener('submit', (e) => {
            loading.style.display = 'block';
            submitBtn.disabled = true;
            error.style.display = 'none';
        });
    </script>
</body>
</html>
